// 导入样式
import 'quill/dist/quill.core.css'
import 'quill/dist/quill.snow.css'
import 'quill/dist/quill.bubble.css'

// 导入组件
import { quillEditor } from 'vue-quill-editor'

console.log('quillEditor', quillEditor)

export default {
  components: {
    quillEditor
  },
  data () {
    return {
      activeStep: 1,
      activeName: 'one',
      // 表单对象  1546630516
      addGoodsForm: {
        goods_name: '',
        goods_cat: [],
        goods_price: '',
        goods_number: '',
        goods_weight: '',
        goods_introduce: '',
        pics: [],
        is_promote: false
      },
      options: [],
      fileList2: [],
      uploadHeaders: {
        Authorization: localStorage.getItem('token')
      },
       editorOption: {
        placeholder: '哈哈'
      },
            htmlstr: '<h1 class="red">这是h1</h1>'
    }
  },
  created () {
    this.mlLoadCategoriesList()
  },
  methods: {
    /**
     * 切换tab
     */
    changeTab (tab) {
      this.activeStep = +tab.index + 1
    },
    /**
     * 下一步
     */
    nextStep (index, name) {
      console.log(index, name)

      this.activeStep = index
      this.activeName = name
    },
    /**
     * 加载商品列表数据
     */
    async mlLoadCategoriesList () {
      const res = await this.$axios.get('/categories', {
        params: {
          type: 3
        }
      })
      console.log(res)
      this.options = res.data.data
    },
    /**
     * 上传图片
     */
    onuploadSuccess (res) {
      this.addGoodsForm.pics.push({
        pic: res.data.tmp_path
      })
      console.log(res.data.tmp_path)
    },
    /**
     * 添加商品
     */
    async addGoods () {
      console.log(11111)

      /* eslint-disable */
      const {
        goods_name,
        goods_cat,
        goods_price,
        goods_number,
        goods_weight,
        goods_introduce,
        pics,
        is_promote
      } = this.addGoodsForm

      const res = await this.$axios.post('/goods', {
        goods_name,
        goods_cat: goods_cat.join(','),
        goods_price,
        goods_number,
        goods_weight,
        goods_introduce,
        pics,
        is_promote
      })

      console.log(res)

      this.$router.push('/goods')

      this.$message({
        type: 'success',
        message: '添加商品成功'
      })
    }
  }
}
